/**
 * Created by Administrator on 2017/3/1 0001.
 */
var textName='';
var resource;
var mode;
var pixiStageW=740;
var pixiStageH=1136;
var pixiStage=new PIXI.Stage(0xFF0000);
var PixiMain={
    create:function () {
        // var ratio=window.devicePixelRatio;

        var pixi_renderer=PIXI.autoDetectRenderer(pixiStageW,pixiStageH,{antialias:true,transparent:true,resolution:1});

        var div_pixi=document.getElementById('div_2d');
        div_pixi.appendChild(pixi_renderer.view);

        var preload=Preload.create();
        preload.init(pixiStage,pixiStageW,pixiStageH);
        var con_whole=new PIXI.Container();
        pixiStage.addChild(con_whole);

        document.addEventListener('Main_LoadComplete',gameStart);
        function gameStart(e) {
            resource=e.detail.resources;
             var game=Game.create();
             pixiStage.addChildAt(game.ui,0);

            threeInit();
        }

        resizeHandlerPIXI();
        window.onresize = resizeHandlerPIXI;
        function resizeHandlerPIXI() {
            pixi_renderer.resize(window.innerWidth, window.innerHeight);
            mode='noBorder';
            switch (mode) {
                case 'exactFit':
                    pixiStage.scale.x = window.innerWidth / pixiStageW;
                    pixiStage.scale.y = window.innerHeight / pixiStageH;
                    break;
                case 'noBorder':
                    pixiStage.scale.x = (window.innerHeight / pixiStageH < window.innerWidth / pixiStageW) ? (window.innerWidth / pixiStageW) : (window.innerHeight / pixiStageH);
                    pixiStage.scale.y = pixiStage.scale.x;
                    break;
                case 'noScale':
                    pixiStage.scale.x = 1;
                    pixiStage.scale.y = 1;
                    break;
                case 'showAll':
                    pixiStage.scale.x = (window.innerHeight / pixiStageH < window.innerWidth / pixiStageW) ? (window.innerHeight / pixiStageH) : (window.innerWidth / pixiStageW);
                    pixiStage.scale.y = pixiStage.scale.x;
                    break;
            }
            pixiStage.x = (window.innerWidth - pixiStageW * pixiStage.scale.x) * .5;
            pixiStage.y = (window.innerHeight - pixiStageH * pixiStage.scale.y) * .5;

            console.log(pixiStage.scale.x,pixiStage.scale.y)

            document.getElementById('text_name').style.width= pixiStage.scale.x*340+'px';
            document.getElementById('text_name').style.height= pixiStage.scale.y*62+'px';
            document.getElementById('text_name').style.left= pixiStage.scale.x*200+'px';
            document.getElementById('text_name').style.top= pixiStage.scale.y*(650+55)+'px';

            document.getElementById('text_tel').style.width= pixiStage.scale.x*340+'px';
            document.getElementById('text_tel').style.height= pixiStage.scale.y*62+'px';
            document.getElementById('text_tel').style.left= pixiStage.scale.x*200+'px';
            document.getElementById('text_tel').style.top= pixiStage.scale.y*(730+60)+'px';

            document.getElementById('img_qr').style.width= pixiStage.scale.x*640+'px';
            document.getElementById('img_qr').style.height= pixiStage.scale.y*1136+'px';
            document.getElementById('img_qr').style.left= pixiStage.scale.x*(50)+pixiStage.x+'px';
            document.getElementById('img_qr').style.top= pixiStage.scale.y*(0)+pixiStage.y+'px';
        };

        // var globalID;
        // globalID=
        requestAnimationFrame(animate);
        // cancelAnimationFrame(globalID);
        function animate() {
            requestAnimationFrame(animate);
            pixi_renderer.render(pixiStage);
            // pd.emitter.update(0.01);
            // for(var i=0;i<game.arr_circle.length;i++)
            // {
            //     if(game.arr_circle[i].ui.scale.x>5)
            // }
        }
    }
}